/* 
 * File:   Sub.cpp
 * Author: Gab'z
 * 
 * Created on 3 juin 2012, 22:39
 */

#include "Sub.h"
#include "../../../Context.h"
#include "../../literal/Stack.h"
#include "../../literal/Complex.h"

namespace calculator {

    Sub::Sub(const std::string name) : BinaryOperator(name) {
    }

    Sub::Sub(const Sub& orig) : BinaryOperator(orig._name) {
    }

    Sub::~Sub() {
    }

    Sub* Sub::clone() const {
        return new Sub(_name);
    }

    const Number* Sub::apply(const Number* n1, const Number* n2) const throw (ArithmeticException) {
        const Complex* co1 = dynamic_cast<const Complex*> (n1);
        const Complex* co2 = dynamic_cast<const Complex*> (n2);
        if ((co1 != 0 || co2 != 0)
                && Context::getInstance()->getParameters()->getComplexMode() == false) throw ArithmeticException("Complex mode OFF");
        const Number* n;
        try {
            n = sub(n1, n2);
        } catch (ArithmeticException& e) {
            throw;
        }
        return n;
    }
}